<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="js/aes.min.js"></script>
<!--<script src="http://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/crypto-js.js"></script>-->
<script ype="text/javascript">
  // ------------AES-------------

  /**
   * AES加密
   * @param plainText 明文
   * @param keyInBase64Str base64编码后的key
   * @returns {string} base64编码后的密文
   */
  function encryptByAES(plainText, keyInBase64Str) {
      let key = CryptoJS.enc.Base64.parse(keyInBase64Str);
      let encrypted = CryptoJS.AES.encrypt(plainText, key, {
          mode: CryptoJS.mode.ECB,
          padding: CryptoJS.pad.Pkcs7,
      });
      // 这里的encrypted不是字符串，而是一个CipherParams对象
      return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
  }

  /**
   * AES解密
   * @param cipherText 密文
   * @param keyInBase64Str base64编码后的key
   * @return 明文
   */
  function decryptByAES(cipherText, keyInBase64Str) {
      let key = CryptoJS.enc.Base64.parse(keyInBase64Str);
      // 返回的是一个Word Array Object，其实就是Java里的字节数组
      let decrypted = CryptoJS.AES.decrypt(cipherText, key, {
          mode: CryptoJS.mode.ECB,
          padding: CryptoJS.pad.Pkcs7,
      });

      return decrypted.toString(CryptoJS.enc.Utf8);
  }

  const secretKey = 'sQPoC/1do9BZMkg8I5c09A==';
  const cipherText = encryptByAES('Hello', secretKey);
  const plainText = decryptByAES(cipherText, secretKey);
  console.log(`Hello加密后的密文为：${cipherText}`);
  console.log(`解密后的内容为：${plainText}`);


</script>
<body>

</body>
</html>